package cn.anosi.controller.auth;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import cn.anosi.controller.BaseController;
import cn.anosi.entity.auth.Permission;

@Controller
@RequestMapping("/permission")
public class PermissionController extends BaseController {
	
	/**
	 * 角色列表分配权限页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/tree", method=RequestMethod.GET)
	public String list(Integer id, Model model){
		model.addAttribute("id", id);
		return "auth/tree";
	}
	
	/**
	 * 获取所有权限的树
	 * @return
	 */
	@RequestMapping(value="/dataTree")
	@ResponseBody
	public List<Permission> dataTree(){
		List<Permission> list = permissionService.findAll();
		return list;
	}
	
	/**
	 * 权限配置页面
	 * @return
	 */
	@RequestMapping(value="/list", method=RequestMethod.GET)
	public String page(){
		return "auth/permission_list";
	}
	
	/**
	 * 权限添加
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.GET)
	public String add(){
		return "auth/permission_add";
	}
	
	/**
	 * 根据id查找权限
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/findOne", method=RequestMethod.GET)
	@ResponseBody
	public Permission findOne(Integer id){
		return permissionService.getById(id);
	}
	
	@RequiresPermissions(value={ "permission:add"})
	@RequestMapping(value="/save", method=RequestMethod.POST)
	@ResponseBody
	public Permission save(Permission permission){
		return permissionService.save(permission);
	}
	
	@RequestMapping(value="/delete", method=RequestMethod.GET)
	@ResponseBody
	public Integer delete(Integer id){
		return permissionService.delete(id);
	}
}
